package net.godcode.t5c.flickr.components;

import java.util.Iterator;

import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.annotations.BeginRender;

import com.aetrion.flickr.Flickr;
import com.aetrion.flickr.REST;
import com.aetrion.flickr.photosets.Photoset;

/**
 * FlickrTest
 * 
 * @author Chris Lewis 24/gen/08 <chris@thegodcode.net>
 * @version $Id$
 */
public class FlickrTest {
	
	@BeginRender
	boolean beginRender(MarkupWriter writer) {
		
		writer.element("table");
		//21287765@N08
		try {
			Flickr f = new Flickr("979eac5daf73512007f9b600c5e321f9", new REST());
			Iterator<Photoset> setsIt = (Iterator<Photoset>)f.getPhotosetsInterface()
				.getList("21287765@N08").getPhotosets().iterator();
			for(int i = 0; setsIt.hasNext() && i < 4; i++) {
				writer.element("tr");
				for(int j = 0; j < 4; j++) {
					writer.element("td");
					writer.element("img", "height", "65", "width", "65", "src", setsIt.next()
						.getPrimaryPhoto().getSmallSquareUrl());
					writer.end();
					writer.end();
				}
				writer.end();
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			writer.element("tr");
			writer.element("td").text("(Exception was thrown)");
			writer.end();
			writer.end();
			e.printStackTrace();
		} finally {
			writer.end();
		}
		
		return false;
	}
	
}